package com.hyx.api.controller.pc_admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hyx.api.domain.bo.CompanyBo;
import com.hyx.api.domain.vo.CompanyVo;
import com.hyx.api.service.pc_admin.ICompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 公司门店列表Controller
 *
 * @author HK
 * @date 2023-10-24
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/company")
public class CompanyController extends BaseController
{
    private final ICompanyService companyService;

    /**
     * 查询公司门店列表列表
     */
    @PreAuthorize("@ss.hasPermi('api:company:list')")
    @GetMapping("/list")
    public AjaxResult list(CompanyBo bo)
    {
        List<CompanyVo> list = companyService.selectCompanyList(bo);
        return success(list);
    }

    /**
     * 导出公司门店列表列表
     */
    @PreAuthorize("@ss.hasPermi('api:company:export')")
    @Log(title = "公司门店列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompanyBo bo)
    {
        List<CompanyVo> list = companyService.selectCompanyList(bo);
        ExcelUtil<CompanyVo> util = new ExcelUtil<>(CompanyVo.class);
        util.exportExcel(response, list, "公司门店列表数据");
    }

    /**
     * 获取公司门店列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(companyService.selectCompanyById(id));
    }

    /**
     * 新增公司门店列表
     */
    @PreAuthorize("@ss.hasPermi('api:company:add')")
    @Log(title = "公司门店列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CompanyBo bo)
    {
        return toAjax(companyService.insertCompany(bo));
    }

    /**
     * 修改公司门店列表
     */
    @PreAuthorize("@ss.hasPermi('api:company:edit')")
    @Log(title = "公司门店列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CompanyBo bo)
    {
        return toAjax(companyService.updateCompany(bo));
    }

    /**
     * 删除公司门店列表
     */
    @PreAuthorize("@ss.hasPermi('api:company:remove')")
    @Log(title = "公司门店列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(companyService.deleteCompanyByIds(ids));
    }
}
